#pragma once

#include "Part.h"
#include "Common/OperateLimitDefine.h"

//统计模块
class OperateLimit
{
public:
	OperateLimit();
	virtual ~OperateLimit();

	void SetType(uint32_t updateType, bool sendClient = false);
	void Attach(const CharacterDBSingleOperateLimitInfo& singleOperateLimitInfo);
	inline uint32_t GetLimitCount() { return mLimitCount; }
	inline uint32_t GetLastTime() { return mLastTime; }
	bool AddLimitCount(PLAYER_ROLE_STATIS_TYPE_E type, uint32_t val);
	bool IsNeedUpdate(uint32_t now);
	void SetLimitCount(uint32_t val);
	uint32_t GetLimitCount(PLAYER_ROLE_STATIS_TYPE_E type);
	inline uint32_t GetUpdateType(){ return mUpdateType; }
	inline void SetLastTime(uint32_t lastTime){ mLastTime = lastTime; }
	inline bool GetSendClient() { return mSendClient; }

private:
	uint32_t	mLimitCount;
	uint32_t	mUpdateType;
	uint32_t    mLastTime;
	bool		mSendClient; //是否要通知给客户端 不通知客户端的数据不予许玩家直接设置
};

class OperateLimitPart : public Part
{
	typedef vector<OperateLimit> OperateLimitMap;

public:
	OperateLimitPart();
	virtual ~OperateLimitPart();
public:
	virtual bool		Init(Creature *pMaster, uint32_t partType, CharacterDBInfo* pCharacterDB = nullptr);
	virtual bool		UnInit();
	virtual bool		OnMsgHandle(uint32_t cmd, const char* data, uint32_t len);
	virtual void		OnExecute(uint16_t nEventID, uint64_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen);
	virtual void		OnTimer(uint32_t nTimerID){}
	virtual bool		SaveDB(CharacterDBInfo& characterDB);
	virtual void		Update(uint64_t tick){}
	//任务每日零点更新
	virtual bool		DailyUpdate(uint64_t unixSec);
	//任务每周零点更新
	virtual bool		WeekUpdate(uint64_t unixSec);
public:
	bool				AddOprateLimit(PLAYER_ROLE_STATIS_TYPE_E type, uint32_t value);
	OperateLimit*		Mut(PLAYER_ROLE_STATIS_TYPE_E type);
	int32_t				GetOprateLimit(PLAYER_ROLE_STATIS_TYPE_E type);
	bool				SetOprateLimit(PLAYER_ROLE_STATIS_TYPE_E type, uint32_t value);
	//获取统计数据 acceptType:接取条件类型 cond1:条件参数1,cond2:条件参数2
	uint64_t GetStatisticData(int32_t acceptType,uint32_t cond1 = 0);
	//共享杀怪记录
	void ShareKillMonsCount(uint32_t monsId,int32_t count);
	//击杀敌对阵营的玩家
	void KillEnemyCampPlayer();
	//属性改变
	void OnAttrChange(uint32_t PANum, int64_t nChangeValue);
private:
	//更新统计数据
	void UpdateStatisticData(int32_t acceptType, uint32_t cond1 = 0, uint64_t cond2 = 0);
	//怪物死亡
	void OnMonsDieEvent(DieEvent &dieEvent);
	//玩家死亡
	void OnPlayerDieEvent(DieEvent &dieEvent);
	//通关副本
	void OnPassEvent(PassDupEvent &passEvent);
	//收集成功
	void OnCollectEvent(CollectOperateEvent &collSucessEvent);
	//制造成功
	void OnMakeEvent(ForgeEquipEvent &makeEvent);
	//制造道具
	void OnMakeItemEvent(MakeOperateEvent &operateEvent);
	//竞技场挑战结果
	void OnArenaResultEvent(ArenaResultEvent &resultEvent);
	//充值
	void OnChargeEvent(PayEvent &payEvent);
	//挖宝
	void OnTreasureEvent(TreasureEvent &treasureEvent);
	//进入场景
	void OnEnterSceneEvent(EnterSceneEvent &enterEvent);
	//精炼
	void OnRefineEvent(EquipRefineEvent &refineEvent);
	//鉴定
	void OnIdentifyEvent(EquipIdentifyEvent &identifyEvent);
	//参加活动
	void OnAttendActEvent(AttendActEvent &attendEvent);
	//完成活动
	void OnFinishActEvent(FinishActEvent &finishEvent);
	//世界聊天
	void OnWorldChatEvent(ChatWorldEvent &chatEvent);
	//击杀仇人
	void OnKillEnemyEvent();
private:
	void				GetOperateLimitStageList(const char* data, uint32_t len);
	void				SetOperateLimitStag(const char* data, uint32_t len);
	void				OnHandleClientAction(const char* data, uint32_t len);


	void				InitStatisticData(const CharacterDBOperateInfo &protoA);
	void				SetStatisticData(CharacterDBOperateInfo &protoA);
private:
	OperateLimitMap		m_mOperateLimit;
	StatisticData		m_statisticData;	//统计数据
};
